using System;
using BitMango;
using Data;
using TMPro;
using UnityEngine;

public class IapUnLockPackagePopupHandler : MonoBehaviour, IPopupWnd, IHandlerBase
{
	public void DoDataExchange()
	{
	}

	public void OnEnterPopup(object param)
	{
		this.isPlayScene = (bool)param;
		this.data = DataContainer<Data.Root>.Data.currentPackage;
		this.coinCount.text = string.Format("{0}", (this.data.iap != null) ? this.data.iap : string.Empty);
		this.desc.text = ((!this.data.isPremium) ? "Complete the previous package\nto unlock this package." : string.Format("You need {0} coins\nto unlock this package.", this.data.iap));
		this.classic.SetActive(!this.data.isPremium);
		this.primium.SetActive(this.data.isPremium);
		if (this.isPlayScene)
		{
			this.unlockBtn.SetSprite("btn_next");
			this.laterBtn.SetActive(true);
			this.videoBtn.SetActive(false);
			this.videoDisableBtn.SetActive(false);
			this.freeBtn.SetActive(false);
		}
		else
		{
			this.unlockBtn.SetSprite("btn_negative");
			this.laterBtn.SetActive(false);
			if (this.data.record.isVideoShowed)
			{
				this.freeBtn.SetActive(true);
				this.videoBtn.SetActive(false);
				this.videoDisableBtn.SetActive(false);
			}
			else if (RewardAd.IsAdInterstitialReward("LevelUpReward"))
			{
				this.freeBtn.SetActive(false);
				this.videoBtn.SetActive(true);
				this.videoDisableBtn.SetActive(false);
			}
			else
			{
				this.freeBtn.SetActive(false);
				this.videoBtn.SetActive(false);
				this.videoDisableBtn.SetActive(true);
			}
		}
	}

	public void OnLeavePopup()
	{
	}

	private void OnClick_buy()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		if (this.data.iap == null)
		{
			return;
		}
		int num = Convert.ToInt32(this.data.iap);
		if (num > Wallet.GetItemCount("blockcoin"))
		{
            //if (Scene.IsPopupOpen() && Scene.CurrentPopup().name.Equals("StorePopup"))
            //{
            //	return;
            //}
            //Scene.ShowPopup("StorePopup", null, null);
            // Scene.QueuePopup("StorePopup");
            // todo show no money
        }
        else
		{
			this.data.record.isLocked = false;
			this.data.SaveContext();
			Wallet.Use("blockcoin", num, null);
			Wallet.Save();
			EconomyLog.SendEconomyLog(LOG_FROM.BUY_IAP, LOG_TYPE.CONSUMPTION, "blockcoin", num);
			DWATTHelper.logEvent("BuyPackage", new object[]
			{
				GameMode.packageMode + "_" + this.data.name,
				string.Empty
			});
			Scene.ClosePopup("IapUnLockPackagePopup", "buy");
		}
	}

	private void OnClickVideoAds()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		RewardAd.ShowVideoAds("PackageUnlock", delegate(bool isSuccess)
		{
			if (isSuccess)
			{
				this.data.record.isVideoShowed = true;
				this.data.SaveContext();
				this.OnEnterPopup(false);
			}
		});
	}

	private void OnClickFreeGame()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		Scene.ClosePopup("IapUnLockPackagePopup", "free");
	}

	private void OnClick_close()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		Scene.ClosePopup("IapUnLockPackagePopup", "close");
	}

	private void OnEscape()
	{
		Scene.ClosePopup("IapUnLockPackagePopup", "close");
	}

	[SerializeField]
	private Camera cam;

	[SerializeField]
	private GameObject curtain;

	public TextMeshPro coinCount;

	public TextMeshPro desc;

	public tk2dSlicedSprite unlockBtn;

	public GameObject videoBtn;

	public GameObject videoDisableBtn;

	public GameObject freeBtn;

	public GameObject laterBtn;

	public GameObject classic;

	public GameObject primium;

	private Package data;

	private bool isPlayScene;
}
